from PySide6.QtWidgets import (
    QDialog, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QDialogButtonBox, QTextEdit
)


class AISettingDialog(QDialog):
    def __init__(self, aiConfig, parent=None):
        super(AISettingDialog, self).__init__(parent)
        self.setWindowTitle("AI 设置(目前只支持本地OLLAMA)")
        self.settings = aiConfig
        self.init_ui()
        self.resize(400, 400)

    def init_ui(self):
        # 创建布局
        layout = QVBoxLayout()

        # 模型类型
        model_layout = QHBoxLayout()
        model_label = QLabel("模型类型:")
        self.model_combo = QComboBox()
        self.model_combo.addItems(self.settings['models'])
        self.model_combo.setCurrentText(self.settings['choose_model'])
        model_layout.addWidget(model_label)
        model_layout.addWidget(self.model_combo)
        layout.addLayout(model_layout)

        # 提示词内容
        prompt_layout = QHBoxLayout()
        prompt_label = QLabel("提示词内容:")
        self.prompt_edit = QTextEdit(self.settings.get("prompt", ""))
        prompt_layout.addWidget(prompt_label)
        prompt_layout.addWidget(self.prompt_edit)
        layout.addLayout(prompt_layout)

        # API 密钥
        # api_key_layout = QHBoxLayout()
        # api_key_label = QLabel("API 密钥:")
        # self.api_key_edit = QLineEdit(self.settings.get("api_key", ""))
        # self.api_key_edit.setEnabled(False)
        # api_key_layout.addWidget(api_key_label)
        # api_key_layout.addWidget(self.api_key_edit)
        # layout.addLayout(api_key_layout)

        # 主机地址
        # host_layout = QHBoxLayout()
        # host_label = QLabel("主机地址:")
        # self.host_edit = QLineEdit(self.settings.get("host", ""))
        # host_layout.addWidget(host_label)
        # host_layout.addWidget(self.host_edit)
        # layout.addLayout(host_layout)

        # 按钮盒
        button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        layout.addWidget(button_box)

        # 设置对话框的布局
        self.setLayout(layout)

    def get_settings(self):
        return {
            "model": self.model_combo.currentText(),
            "prompt": self.prompt_edit.toPlainText()
        }
